		TITLE	PARSE_FN - Copyright (c) SLR Systems 1994

		INCLUDE	MACROS
		INCLUDE	IO_STRUC

		PUBLIC	PARSE_FILENAME
;		PUBLIC	FNTBL

		.DATA

		externdef	FNTBL:byte

		.CODE	FILEPARSE_TEXT

		externdef	_parse_filename:proc
		externdef	_force_path:proc

PARSE_FILENAME	PROC
	push	EAX
	call	_parse_filename
	add	ESP,4
	ret

		;
		;EAX IS NFN_STRUCT
		;(LENGTH IS ALREADY SET, AND TEXT IS THERE)
		;
		;RETURNS:
		;	EAX IS NFN_STRUCT
		;
		PUSHM	EDI,ESI,EBX
		MOV	ESI,EAX
		ASSUME	ESI:PTR NFN_STRUCT

		XOR	EAX,EAX
		MOV	EDI,ESI
		ASSUME	EDI:PTR NFN_STRUCT

		MOV	[ESI].NFN_PATHLEN,EAX
		MOV	[ESI].NFN_PRIMLEN,EAX
		MOV	[ESI].NFN_EXTLEN,EAX
		MOV	DPTR [ESI].NFN_FLAGS,EAX

		MOV	ECX,[ESI].NFN_TOTAL_LENGTH
		LEA	ESI,[ESI].NFN_TEXT
		MOV	EBX,OFF FNTBL
;		MOV	EDX,ESI		;SAVE START OF FILENAME IN DX
		MOV	DPTR [ESI+ECX],EAX	;ZERO AT END
		LEA	ESI,[ESI+ECX-1]	;ESI IS AT THE LAST CHAR OF TOKEN
		;
		;SCAN FORWARDS LOOKING FOR AMBIGUOUS CHARACTERS
		;
		TEST	ECX,ECX
		JZ	L9$
		;
		;OK, NOW SCAN BACKWARDS FOR EXTENT OR PATH STUFF
		;
		;
		;SKIP TRAILING SPACES
		;
L30$:
		MOV	AL,[ESI]
		DEC	ESI
		CMP	AL,' '
		JNZ	L31$
		DEC	ECX
		MOV	[EDI].NFN_TOTAL_LENGTH,ECX
		JNZ	L30$
		JMP	L9$

L3$:
		DEC	ESI
L31$:
		MOV	AL,[EBX+EAX]
		DEC	ECX
		TEST	AL,MASK FNTBL_PATH_SEPARATOR+MASK FNTBL_DOT+MASK FNTBL_AMBIGUOUS
		JNZ	L32$
		MOV	AL,[ESI]
		TEST	ECX,ECX
		JNZ	L3$
		JMP	DO_PRIMARY2

L32$:
		TEST	AL,MASK FNTBL_AMBIGUOUS
		JZ	L33$
		OR	[EDI].NFN_FLAGS,MASK NFN_AMBIGUOUS
		MOV	AL,[ESI]
		OR	ECX,ECX
		JNZ	L3$
		JMP	DO_PRIMARY2

L55$:
		TEST	AL,MASK FNTBL_PATH_SEPARATOR + MASK FNTBL_AMBIGUOUS
		JZ	DO_PRIMARY2
		TEST	AL,MASK FNTBL_PATH_SEPARATOR
		JNZ	DO_PRIMARY1
		OR	[EDI].NFN_FLAGS,MASK NFN_AMBIGUOUS
		JMP	DO_PRIMARY1

L33$:
		TEST	AL,MASK FNTBL_DOT
		JZ	DO_PRIMARY1
		;
		;GOT A '.', SO STORE EXTENT LENGTH PLEASE
		;
		MOV	EAX,[EDI].NFN_TOTAL_LENGTH
		OR	[EDI].NFN_FLAGS,MASK NFN_EXT_SPECIFIED
		SUB	EAX,ECX
		CMP	EAX,1
		JZ	L4$
L41$:
		MOV	[EDI].NFN_EXTLEN,EAX
L49$:
		;
		;NOW LOOK ONLY FOR END-OF-PRIMARY...
		;
		XOR	EAX,EAX
		TEST	ECX,ECX
		JZ	L9$
L5$:
		MOV	AL,[ESI]
		DEC	ESI
		DEC	ECX
		MOV	AL,[EBX+EAX]
		JZ	L55$
		TEST	AL,MASK FNTBL_PATH_SEPARATOR + MASK FNTBL_AMBIGUOUS
		JZ	L5$
		TEST	AL,MASK FNTBL_PATH_SEPARATOR
		JNZ	DO_PRIMARY1
		OR	[EDI].NFN_FLAGS,MASK NFN_AMBIGUOUS
		JMP	L5$

DO_PRIMARY1:
		INC	ECX
DO_PRIMARY:
;		INC	ESI
DO_PRIMARY2:
		MOV	EAX,[EDI].NFN_TOTAL_LENGTH
		SUB	EAX,[EDI].NFN_EXTLEN
		SUB	EAX,ECX
		MOV	[EDI].NFN_PRIMLEN,EAX
		JZ	DP_3
		OR	[EDI].NFN_FLAGS,MASK NFN_PRIM_SPECIFIED
DP_3:
		;
		;NOW, CX IS # OF BYTES IN A PATH-SPEC
		;
		TEST	ECX,ECX
		JZ	L9$
		MOV	[EDI].NFN_PATHLEN,ECX
		OR	[EDI].NFN_FLAGS,MASK NFN_PATH_SPECIFIED
L9$:
		;
		;ALL DONE, CONGRATS!
		;
		BITT	FORCE_PATH
		JNZ	FP_1
L99$:
		POPM	EBX,ESI
		MOV	EAX,EDI
		POP	EDI
		RET

L4$:
		;
		;JUST A DOT, REMOVE IT...
		;
		BITT	FORCE_PATH
		JNZ	L41$
		DEC	[EDI].NFN_TOTAL_LENGTH
		JMP	L49$

FP_1:
	push	EDI
	call	_force_path
	add	ESP,4
	jmp	L99$
		;
		;IF PRIMLEN OR EXTLEN !=0, MAKE THEM ZERO AND ADD A \ AT END
		;
		MOV	EBX,[EDI].NFN_PRIMLEN
		AND	[EDI].NFN_FLAGS,NOT (MASK NFN_PRIM_SPECIFIED+MASK NFN_EXT_SPECIFIED)
		ADD	EBX,[EDI].NFN_EXTLEN
		JZ	L8$
		INC	EBX
		XOR	EAX,EAX
		ADD	EBX,[EDI].NFN_PATHLEN
		MOV	[EDI].NFN_PRIMLEN,EAX
		MOV	[EDI].NFN_PATHLEN,EBX
		MOV	[EDI].NFN_EXTLEN,EAX
		MOV	BPTR [EDI+EBX].NFN_TEXT-1,'\'
		INC	[EDI].NFN_TOTAL_LENGTH
		OR	[EDI].NFN_FLAGS,MASK NFN_PATH_SPECIFIED
L8$:
		JMP	L99$

PARSE_FILENAME	ENDP


		.DATA		;MUST BE IN DATA SEGMENT, AS WE MODIFY IT...

;FNTBL		LABEL	BYTE
		;
		;ILLEGAL HPFS FILENAME CHARS ARE:
		;
		; 0-1FH, " * + , / : ; < = > ? [ \ ] |
		;
		;WE ALLOW PATH SEPARATORS \ / :
		;WE ALLOW AMBIGUOUS CHARS ? *
		;
		DB	MASK FNTBL_ILLEGAL+MASK SYMTBL_ILLEGAL	;00 NUL
		DB	MASK FNTBL_ILLEGAL+MASK SYMTBL_ILLEGAL	;01 SOH
		DB	MASK FNTBL_ILLEGAL+MASK SYMTBL_ILLEGAL	;02
		DB	MASK FNTBL_ILLEGAL+MASK SYMTBL_ILLEGAL	;03
		DB	MASK FNTBL_ILLEGAL+MASK SYMTBL_ILLEGAL	;04
		DB	MASK FNTBL_ILLEGAL+MASK SYMTBL_ILLEGAL	;05
		DB	MASK FNTBL_ILLEGAL+MASK SYMTBL_ILLEGAL	;06
		DB	MASK FNTBL_ILLEGAL+MASK SYMTBL_ILLEGAL	;07 BEL
		DB	MASK FNTBL_ILLEGAL+MASK SYMTBL_ILLEGAL	;08 BS
		DB	MASK FNTBL_ILLEGAL+MASK SYMTBL_ILLEGAL	;09 TAB
		DB	MASK FNTBL_ILLEGAL+MASK SYMTBL_ILLEGAL	;0A LF
		DB	MASK FNTBL_ILLEGAL+MASK SYMTBL_ILLEGAL	;0B
		DB	MASK FNTBL_ILLEGAL+MASK SYMTBL_ILLEGAL	;0C
		DB	MASK FNTBL_ILLEGAL+MASK SYMTBL_ILLEGAL	;0D CR
		DB	MASK FNTBL_ILLEGAL+MASK SYMTBL_ILLEGAL	;0E
		DB	MASK FNTBL_ILLEGAL+MASK SYMTBL_ILLEGAL	;0F
		DB	MASK FNTBL_ILLEGAL+MASK SYMTBL_ILLEGAL	;10
		DB	MASK FNTBL_ILLEGAL+MASK SYMTBL_ILLEGAL	;11
		DB	MASK FNTBL_ILLEGAL+MASK SYMTBL_ILLEGAL	;12
		DB	MASK FNTBL_ILLEGAL+MASK SYMTBL_ILLEGAL	;13
		DB	MASK FNTBL_ILLEGAL+MASK SYMTBL_ILLEGAL	;14
		DB	MASK FNTBL_ILLEGAL+MASK SYMTBL_ILLEGAL	;15
		DB	MASK FNTBL_ILLEGAL+MASK SYMTBL_ILLEGAL	;16
		DB	MASK FNTBL_ILLEGAL+MASK SYMTBL_ILLEGAL	;17
		DB	MASK FNTBL_ILLEGAL+MASK SYMTBL_ILLEGAL	;18
		DB	MASK FNTBL_ILLEGAL+MASK SYMTBL_ILLEGAL	;19
		DB	MASK FNTBL_ILLEGAL+MASK SYMTBL_ILLEGAL	;1A
		DB	MASK FNTBL_ILLEGAL+MASK SYMTBL_ILLEGAL	;1B ESC
		DB	MASK FNTBL_ILLEGAL+MASK SYMTBL_ILLEGAL	;1C
		DB	MASK FNTBL_ILLEGAL+MASK SYMTBL_ILLEGAL	;1D
		DB	MASK FNTBL_ILLEGAL+MASK SYMTBL_ILLEGAL	;1E
		DB	MASK FNTBL_ILLEGAL+MASK SYMTBL_ILLEGAL	;1F

		DB	MASK FNTBL_ILLEGAL+MASK SYMTBL_ILLEGAL	;20 SPACE
		DB	0					;21 !
		DB	MASK FNTBL_ILLEGAL			;22 "
		DB	0					;23 #
		DB	0					;24 $
		DB	0					;25 %
		DB	0					;26 &
		DB	0					;27 '
		DB	MASK SYMTBL_ILLEGAL			;28 (
		DB	MASK SYMTBL_ILLEGAL			;29 )	;ILLEGAL IN FILE NAMES IF '(' OVERLAY FOUND
		DB	MASK FNTBL_AMBIGUOUS+MASK SYMTBL_ILLEGAL;2A *
		DB	MASK FNTBL_ILLEGAL+MASK SYMTBL_ILLEGAL	;2B +
		DB	MASK FNTBL_ILLEGAL+MASK SYMTBL_ILLEGAL	;2C ,
		DB	0					;2D -
		DB	MASK FNTBL_DOT				;2E .
		DB	MASK FNTBL_ILLEGAL+MASK SYMTBL_ILLEGAL	;2F /	;ILLEGAL FOR MSCMDLIN SUPPORT...

		DB	MASK IS_NUMERIC				;30 0
		DB	MASK IS_NUMERIC				;31 1
		DB	MASK IS_NUMERIC				;32 2
		DB	MASK IS_NUMERIC				;33 3
		DB	MASK IS_NUMERIC				;34 4
		DB	MASK IS_NUMERIC				;35 5
		DB	MASK IS_NUMERIC				;36 6
		DB	MASK IS_NUMERIC				;37 7
		DB	MASK IS_NUMERIC				;38 8
		DB	MASK IS_NUMERIC				;39 9
		DB	MASK FNTBL_PATH_SEPARATOR+MASK SYMTBL_ILLEGAL	;3A :
		DB	MASK FNTBL_ILLEGAL+MASK SYMTBL_ILLEGAL	;3B ;
		DB	MASK FNTBL_ILLEGAL			;3C <
		DB	MASK FNTBL_ILLEGAL+MASK SYMTBL_ILLEGAL	;3D =
		DB	MASK FNTBL_ILLEGAL			;3E >
		DB	MASK FNTBL_AMBIGUOUS			;3F ?

		DB	0					;40 @
		DB	MASK IS_ALPHA				;41 A
		DB	MASK IS_ALPHA				;42 B
		DB	MASK IS_ALPHA				;43 C
		DB	MASK IS_ALPHA				;44 D
		DB	MASK IS_ALPHA				;45 E
		DB	MASK IS_ALPHA				;46 F
		DB	MASK IS_ALPHA				;47 G
		DB	MASK IS_ALPHA				;48 H
		DB	MASK IS_ALPHA				;49 I
		DB	MASK IS_ALPHA				;4A J
		DB	MASK IS_ALPHA				;4B K
		DB	MASK IS_ALPHA				;4C L
		DB	MASK IS_ALPHA				;4D M
		DB	MASK IS_ALPHA				;4E N
		DB	MASK IS_ALPHA				;4F O

		DB	MASK IS_ALPHA				;50 P
		DB	MASK IS_ALPHA				;51 Q
		DB	MASK IS_ALPHA				;52 R
		DB	MASK IS_ALPHA				;53 S
		DB	MASK IS_ALPHA				;54 T
		DB	MASK IS_ALPHA				;55 U
		DB	MASK IS_ALPHA				;56 V
		DB	MASK IS_ALPHA				;57 W
		DB	MASK IS_ALPHA				;58 X
		DB	MASK IS_ALPHA				;59 Y
		DB	MASK IS_ALPHA				;5A Z
		DB	MASK FNTBL_ILLEGAL			;5B [
		DB	MASK FNTBL_PATH_SEPARATOR		;5C \
		DB	MASK FNTBL_ILLEGAL			;5D ]
		DB	0					;5E ^
		DB	0					;5F _

		DB	0					;60 `
		DB	MASK IS_ALPHA				;61 a
		DB	MASK IS_ALPHA				;62 b
		DB	MASK IS_ALPHA				;63 c
		DB	MASK IS_ALPHA				;64 d
		DB	MASK IS_ALPHA				;65 e
		DB	MASK IS_ALPHA				;66 f
		DB	MASK IS_ALPHA				;67 g
		DB	MASK IS_ALPHA				;68 h
		DB	MASK IS_ALPHA				;69 i
		DB	MASK IS_ALPHA				;6A j
		DB	MASK IS_ALPHA				;6B k
		DB	MASK IS_ALPHA				;6C l
		DB	MASK IS_ALPHA				;6D m
		DB	MASK IS_ALPHA				;6E n
		DB	MASK IS_ALPHA				;6F o

		DB	MASK IS_ALPHA				;70 p
		DB	MASK IS_ALPHA				;71 q
		DB	MASK IS_ALPHA				;72 r
		DB	MASK IS_ALPHA				;73 s
		DB	MASK IS_ALPHA				;74 t
		DB	MASK IS_ALPHA				;75 u
		DB	MASK IS_ALPHA				;76 v
		DB	MASK IS_ALPHA				;77 w
		DB	MASK IS_ALPHA				;78 x
		DB	MASK IS_ALPHA				;79 y
		DB	MASK IS_ALPHA				;7A z
		DB	0					;7B {
		DB	MASK FNTBL_ILLEGAL			;7C |
		DB	0					;7D }
		DB	0					;7E ~
		DB	0					;7F

		db	80h dup (0)

		END

